<template>
	<view class="consum-page">
		<navBar title="材料消耗明细" goBackUrl="/pages/homePage/homePage" @goBack="goBack"></navBar>
		<template>
			<view class="material_box" v-for="item in dataList">
				<view class="top-title" v-if="getCountNum(item.list) > 0">
					<view class="">{{item.name}}</view>
					<view class="">{{getCountNum(item.list)}}吨</view>
				</view>
				<view class="box-spec" v-for="key in item.list">
					<view v-if="key.costNum > 0">
						<view class="top-sepc">
							<view class="">规格型号:{{key.specificationModel}}</view>
						</view>
						<view class="top-botm">
							<view class="">所属基地:{{key.stationName}}</view>
							
							<template>
								<view class="" style="display: flex;align-items: center;">
									消耗量:
									<u-number-box :min="0" v-model="key.costNum" @change="valChange" :disablePlus="true">
									</u-number-box>
								</view>
							</template>
						</view>
					</view>
				</view>
			</view>
			<view class="btn_box">
				<view class="btn_group">
					<u-button type="primary" text="确定" @click="saveBtn"></u-button>
				</view>
			</view>
		</template>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dataList: [],
				childrenData:[]
			}
		},
		onLoad(options) {
			this.eventChannel = this.getOpenerEventChannel();
			this.eventChannel.on('sendData', (data) => {
				console.log(data, 'sendData')
				let arr = data.data
				this.deepData = data.data //保存一份数据
				this.dataList = arr[0].list
				console.log(this.dataList,'52行')
			})
			
		},
		methods: {
			// 返回上一级
			goBack(url) {
				uni.navigateBack({
					
				})
				// uni.switchTab({
				// 	url: url
				// })
			},
			// 步进器改变
			valChange() {
				
			},
			// 保存按钮
			saveBtn() {
				console.log(this.deepData, '**********')
				// uni.setStorageSync('materTreeData',this.dataList)
				uni.navigateBack({
					success: () => {
						this.eventChannel.emit("getMaterTree", {
							data: {
								list: this.deepData
							}
						})
					}
				})
			},
			//获取各个材料消耗量总数
			getCountNum(arr) {
				let count = 0
				arr.forEach(it => {
					count += it.costNum
				})
				return count.toFixed(2)
			},
			valChange(val) {
				// console.log(val)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.btn_box {
		height: 100rpx;

		.btn_group {
			display: flex;
			align-items: center;
			justify-content: space-between;
			// margin-top: 100rpx;
			position: fixed;
			bottom: 0;
			width: 100%;

		}
	}

	.material_box {
		background-color: #fff;

		.top-title {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 20rpx 30rpx;
			border-bottom: 1px solid #efefef;
			font-size: 38rpx;
		}

		.box-spec {

			.top-sepc {
				padding: 12rpx 6rpx;
			}

			.top-botm {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 12rpx 6rpx;
				border-bottom: 1px solid #efefef;
			}
		}



	}
</style>
